package edu.zut.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 获取请求url的路劲信息：
 * url属于请求中的内容
 * http://localhost:8080/Web205_206/showInfo   Get
 * 假设：发起一个请求，映射到ShowInfoServlet，接着解析这个请求
 * doGet方法中的形参request表示的就是http请求对象，和请求有关的信息都在request中
 */
public class ShowInfoServlet extends HttpServlet {

    /**
     *
     * @param request http请求对象
     * @param response http响应对象
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //url环境信息
        String contextPath = request.getContextPath();
        System.out.println("contextPath = " + contextPath);
        String uri = request.getRequestURI();
        System.out.println("uri = " + uri);
        StringBuffer url = request.getRequestURL();
        System.out.println("url = " + url);
        //获取请求的资源路劲
        String servletPath = request.getServletPath();
        System.out.println("servletPath = " + servletPath);
        //获取资源路劲的路劲信息
        String pathInfo = request.getPathInfo();
        System.out.println("pathInfo = " + pathInfo);
        //获取请求的方式
        String method = request.getMethod();
        System.out.println("method = " + method);

    }
}
